//
//  TuijianCell2.m
//  New
//
//  Created by 才诗琦 on 16/1/19.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//
#define W self.contentView.frame.size.width-110
#import "TuijianCell2.h"

@implementation TuijianCell2
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.imag = [[UIImageView alloc] init];
        _imag.layer.cornerRadius = 5;
        _imag.clipsToBounds = YES;
        [self.contentView addSubview: _imag];
        [_imag release];
        
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview: _titleLabel];
        [_titleLabel release];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.numberOfLines = 0;
        self.contentLabel.font = [UIFont systemFontOfSize:15];
        _contentLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_contentLabel];
        [_contentLabel release];
        
        self.commentCountLabel = [[UILabel alloc] init];
        _commentCountLabel.textColor = [UIColor grayColor];
        _commentCountLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_commentCountLabel];
        [_commentCountLabel release];
        
        
    }
    
    return self;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imag.frame = CGRectMake(5, 20, 80, 80);
    self.titleLabel.frame = CGRectMake(100, 15, self.contentView.frame.size.width-110, 30);
    
    CGFloat h = [[self class] heightWithText:_contentLabel.text width:W];
    self.contentLabel.frame =CGRectMake(100, 40, self.contentView.frame.size.width-110, h);
    self.commentCountLabel.frame = CGRectMake(270, 40 + h, 120, 20);
   
    
    
    
}
//内容自适应高度
+(CGFloat)heightWithText:(NSString *)str width:(NSInteger)wi
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(wi, 1000);
    CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
